package es.kivitel.android.sms.gui;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import java.util.Calendar;
import java.util.List;

import es.kivitel.android.sms.kernel.BriefEvent;

class EventAdapterView extends LinearLayout {        
        public EventAdapterView(Context context, 
								BriefEvent evt ) {
            super( context );

            this.setOrientation(HORIZONTAL);        
            LinearLayout.LayoutParams imgParams = 
                new LinearLayout.LayoutParams(20, LayoutParams.WRAP_CONTENT);
			ImageView typeControl = new ImageView( context );
			typeControl.setImageResource( evt.getTypeResource() );
			ImageView stateControl = new ImageView( context );
			stateControl.setImageResource( evt.getStateResource() );
			addView( typeControl, imgParams );			
			addView( stateControl, imgParams );			
 
            LinearLayout.LayoutParams evtParams = 
                new LinearLayout.LayoutParams(80, LayoutParams.WRAP_CONTENT);
            evtParams.setMargins(1, 1, 1, 1);
            TextView evtControl = new TextView( context );
            evtControl.setText(  evt.getSendingdate().get(Calendar.DAY_OF_MONTH)+"/"
            				   + evt.getSendingdate().get(Calendar.MONTH)+"/"
            				   + evt.getSendingdate().get(Calendar.YEAR)+" "
            				   + evt.getSendingdate().get(Calendar.HOUR)+":"
            				   + evt.getSendingdate().get(Calendar.MINUTE));
            evtControl.setTextSize(14f);
            evtControl.setTextColor(Color.WHITE);
            addView( evtControl, evtParams);       
            
            LinearLayout.LayoutParams extraParams = 
                new LinearLayout.LayoutParams(100, LayoutParams.WRAP_CONTENT);
            extraParams.setMargins(1, 1, 1, 1);
            TextView extraControl = new TextView(context);
            extraControl.setText( evt.destination );
            extraControl.setTextSize( 14f );
            extraControl.setTextColor(Color.WHITE);
            addView( extraControl, extraParams);            
            extraParams.width=LayoutParams.WRAP_CONTENT;
            extraControl = new TextView(context);
            extraControl.setText( evt.getComment() );
            extraControl.setTextSize( 14f );
            extraControl.setTextColor(Color.WHITE);
            addView( extraControl, extraParams);            
			
        }
}

public class EventAdapter extends BaseAdapter {

    private Context context;
    private List<BriefEvent> eventList;

    public EventAdapter(Context context, List<BriefEvent> eventList ) { 
        this.context = context;
        this.eventList = eventList;

    }

    public int getCount() {                        
        return eventList.size();
    }

    public Object getItem(int position) {     
        return eventList.get(position);
    }

    public long getItemId(int position) {  
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) { 
        BriefEvent event = eventList.get(position);

        return new EventAdapterView(this.context, event );
    }

}
